<template>
  <div :style="{textAlign:'left'}">
    <el-form :model="formData" label-width="100px">
      <el-form-item label="用户名">
        <el-input v-model="formData.username"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="formData.password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="handleSave" type="primary">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import md5 from 'md5'
export default {
  name: 'User',
  props: ['formData'],
  methods: {
    handleSave: function() {
      let body = { username: this.formData.username, password: md5(this.formData.password) }

      this.$api.saveUser(body).then(res=>{
        this.$message({
          message: '保存成功',
          type: 'success'
        })
        this.$emit('success')
      })
    }
  }
}
</script>

<style>

</style>
